package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.PmsProductFullReduction;
import com.itheima.domain.PmsProductLadder;
import com.itheima.mapper.PmsProductLadderMapper;
import com.itheima.service.db.PmsProductLadderService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductLadderServiceImpl implements PmsProductLadderService {
    @Autowired
    PmsProductLadderMapper pmsProductLadderMapper;

    @Override
    public List<PmsProductLadder> selectByProductId(Integer id) {
        LambdaQueryWrapper<PmsProductLadder> lqw=new LambdaQueryWrapper<>();
        lqw.eq(PmsProductLadder::getProductId,id);
        return pmsProductLadderMapper.selectList(lqw);
    }

    @Override
    public void updateByProductId(Integer id, List<PmsProductLadder> PmsProductLadderList) {
        LambdaQueryWrapper<PmsProductLadder> lqw=new LambdaQueryWrapper<>();
        lqw.eq(PmsProductLadder::getProductId,id);
        pmsProductLadderMapper.delete(lqw);

        for (PmsProductLadder PmsProductLadder : PmsProductLadderList) {
            PmsProductLadder.setProductId(id.longValue());
            pmsProductLadderMapper.insert(PmsProductLadder);
        }

    }

    @Override
    public void save(Long productId, List<PmsProductLadder> productLadderList) {
        for (PmsProductLadder PmsProductLadder : productLadderList) {
            PmsProductLadder.setProductId(productId);
            pmsProductLadderMapper.insert(PmsProductLadder);
        }
    }
}
